package com.guigu.qxl.controller;

import com.guigu.pojo.SysUsers;
import com.guigu.qxl.service.SysUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("SysUsers")
public class SysUsersController {
    @Autowired
    SysUsersService sysUsersService;

    @RequestMapping("login")
    public Map login(SysUsers sysUsers,HttpSession session){
        Map map=new HashMap();
        map.put("code","-1");
        map.put("msg","登录失败");
        SysUsers sysUsers1=sysUsersService.login(sysUsers);
        if(sysUsers1!=null){
            map.put("code","1");
            map.put("msg","登录成功");
            session.setAttribute("sysUsers",sysUsers1);
        }
        return map;
    }

    @PostMapping("exit")
    public Map exit(HttpSession session){
        Map map=new HashMap();
        map.put("code","1");
        map.put("msg","退出成功");
        session.setAttribute("sysUsers",null);
        return map;
    }
}
